<!--
 * @Author: wangding
 * @Date: 2020-11-11 15:58:31
 * @LastEditTime: 2020-12-24 17:51:48
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\device\sale\add.vue
-->
<template>
    <div class="buyPage-main-box-add">
        <el-dialog
        :title="$t('import')"
        :visible="newVisiblePvModules"
        width="35%"
        @close="()=>{$store.commit('setNewVisiblePvModules',false)}"
        :close-on-click-modal='false'
        >   
            <el-row :gutter="20">
                <el-col :span="19" :offset="2">
                    <el-form ref="form" :model="form" label-width="120px" >
                       
                        <el-form-item :label="$t('version.versionService.fileURL')" prop="file" :rules="[{ required: true, message: $t('index_js_notNull')}]">
                            <baseFile v-model="form.file" style="width:100%"  >
                            </baseFile>
                        </el-form-item>
                        <el-form-item > 
                            <el-button type="primary" @click="downloadModal">{{$t('NMI.downloadModelVpp')}}</el-button>
                        </el-form-item>
                    </el-form>
                </el-col>
            </el-row>
            <span slot="footer" class="dialog-footer">
                <el-button @click="()=>{$store.commit('setNewVisiblePvModules',false)}">{{$t('cancel')}}</el-button>
                <el-button type="primary" @click="save('form')">{{$t('sure')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import baseFile from '../../../components/common/baseFileInput'
export default {
    components: {
        baseFile
    },
    props: {
        groupId:{
            type:String,
            default:''
        },
    },
    data() {
        return {
            typeList:[{
                id:'0',
                text:"VPP"
            },{
                id:'1',
                text:"SAPN"
            }],
            form:{
                file:"",
            },
        };
    },
    computed: {
        newVisiblePvModules(){
            return this.$store.state.sysStore.newVisiblePvModules
        }
    },
    watch: {

    },
    created() {

    },
    mounted() {

    },
    methods: {
        downloadModal(){
            this.comm.windowOpen('/resource/files/vpp/Group_VPP_Template.xlsx')
        },
        async vppinverterImportGroupInfo(){
            let data = await this.API.vppinverterImportGroupInfo(Object.assign({},this.form,{groupId:this.groupId}))
            if(data.success){
                this.$emit('uploadData',true)
                this.$store.commit('setNewVisiblePvModules',false)
                if(data.object){
                    var msgStr = ''
                    if(data.object.illegalList.length>0){
                        msgStr +=`${$t('NMI.importModalMsg1')}:${[...data.object.illegalList]},`
                    }
                    if(data.object.duplicateNmiList.length>0){
                        msgStr +=`${$t('NMI.errorMsg4')}:${[...data.object.duplicateNmiList]},`
                    }
                    if(data.object.duplicateList.length>0){
                        msgStr +=`${$t('NMI.errorMsg1')}:${[...data.object.duplicateList]},`
                    }
                    if(data.object.notExistList.length>0){
                        msgStr +=`${$t('NMI.errorMsg2')}:${[...data.object.notExistList]},`
                    }
                    msgStr += `${$t('NMI.importModalMsg2')}`
                    if(data.object.illegalList.length == 0&&data.object.duplicateList.length == 0&&data.object.notExistList.length == 0&&data.object.duplicateNmiList.length == 0){
                        this.comm.showMsg(true, this.$t('index.control_success'))
                        return
                    }
                   this.comm.showMsg(false,msgStr)
                }
            }else{
                this.comm.showMsg(false,this.$t('index.control_fail'))
            }
        },
        save(formName){
            this.$refs[formName].validate((valid) => {
              if (valid) {
                  this.vppinverterImportGroupInfo()
              } else {
                console.log('error submit!!');
                return false;
              }
            });
        },
    },
};
</script>

<style  lang="less" >
.buyPage-main-box-add{
    .el-form-item__content{
        display: flex;
    }
    .icon-fontsize{
        font-size: 25px;
        margin-left: 10px;
        display: block;
        width: 25px;
        height: 33px;
    }
}
</style>
